package com.cardgame.model.card;

import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;

import java.util.HashMap;
import java.util.Map;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
        @JsonSubTypes.Type(value = RoleCard.class, name = "role"),
        @JsonSubTypes.Type(value = ActionCard.class, name = "action"),
        @JsonSubTypes.Type(value = TotalWeaponCard.class, name = "total_weapon"),
        @JsonSubTypes.Type(value = RoleWeaponCard.class, name = "role_weapon")
})
@Getter
@Setter // ✅ 添加 Setter 以支持反序列化
@Component
public class Card implements ICard {
    private Integer id;
    private String name;
    private String imageUrl;
    private String introduction;
    @JsonProperty(value = "type", access = JsonProperty.Access.READ_WRITE)
    private String type;
    private Integer price;
    private Integer cost;

    public Card() {
    }

    public Card(Integer id, String name, String imageUrl, String introduction, String type, Integer price,
            Integer cost) {
        this.id = id;
        this.name = name;
        this.imageUrl = imageUrl;
        this.introduction = introduction;
        this.type = type;
        this.price = price;
        this.cost = cost;
    }

    @Override
    public String toString() {
        return "Card [id=" + id + ", name=" + name + ", imageUrl=" + imageUrl + ", introduction=" + introduction
                + ", type=" + type + ", price=" + price + ", cost=" + cost + "]";
    }

    Map<String, Object> toMap() {
        return new HashMap<>(Map.of(
            "id", id,
            "name", name,
            "imageUrl", imageUrl,
            "introduction", introduction,
            "type", type,
            "price", price,
            "cost", cost
        ));
    }
}
